package mysql

import (
	"bluebell/models"
	"database/sql"

	"go.uber.org/zap"
)

func GetCommunityAll() (communityList []*models.Community, err error) {
	sqlstr := "select community_id, community_name from community"
	if err := db.Select(&communityList, sqlstr); err != nil {
		if err == sql.ErrNoRows {
			zap.L().Warn("there is no community", zap.Error(err))
			err = nil
		}
	}
	return
}

// GetCommunityDetailByID 根据ID查询社区详情
func GetCommunityDetailByID(id int64) (detail *models.CommunityDetail, err error) {
	detail = &models.CommunityDetail{}
	sqlstr := "select community_id, community_name, introduction, create_time from community where community_id = ?"
	if err := db.Get(detail, sqlstr, id); err != nil {
		if err == sql.ErrNoRows {
			err = ErrorInvalidID
		}
	}
	return detail, err
}
